layui.use(['form', 'laydate'], function () {

    var form = layui.form;
    var laydate = layui.laydate;
    var fileType = null;
    var oper = GetQueryStringEncode("oper");
    if(oper){
    	var result = parent.dataDetail;
		var orderNo = result.order_no;
    	if(oper == 'detail'){
    		fileType = 2;
    	}else if(oper == 'pay'){
    		fileType = 1;
    	}
    	var pram = {
    			"orderNo":orderNo,
    			"fileType":fileType
    	}
    	$.ajax({
			url: hostUrl+'/purchaseIntentioAttach/getIntentioAttach',
	        type: "get",
	        data: pram,
	        dataType: "json",
	        success: function(data) {
	        	 if(data.status == 1){
	        		 var result = data.data;
	        		    // 图片处理 数组
	        		    if(result.length > 0){
	        		    	for (var i = 0; i < result.length; i++) {
	        		    		if(fileType == 2){
	        		    			// 附件类型（融资） 1-计算服务协议 2-借款支用申请书 3-企业借款合同 4-委托付款确认书 5-最高额保证合同 6-汽车代采服务协议 7-产品购销协议；（全款）1-汽车采购合同；
	        		    			if(result[i].fileType == '2'){
	        		    				if(result.length == 1){
	        		    					$("#qccgImg").html(createImg(result[i].filePath));
	        		    				}else{
	        		    					if (result[i].filePath) {
	        		    						if (result[i].attachType == 1) {
	        		    							$("#jsfwImg").html(createImg(result[i].filePath));
	        		    						} else if (result[i].attachType == 2) {
	        		    							$("#jkzyImg").html(createImg(result[i].filePath));
	        		    						} else if (result[i].attachType == 3) {
	        		    							$("#qyjkImg").html(createImg(result[i].filePath));
	        		    						} else if (result[i].attachType == 4) {
	        		    							$("#wtfkImg").html(createImg(result[i].filePath));
	        		    						} else if (result[i].attachType == 5) {
	        		    							$("#zgedImg").html(createImg(result[i].filePath));
	        		    						} else if (result[i].attachType == 6) {
	        		    							$("#qcdcImg").html(createImg(result[i].filePath));
	        		    						}else if (result[i].attachType == 7) {
	        		    							$("#cpxyImg").html(createImg(result[i].filePath));
	        		    						}
	        		    					}
	        		    				}
	        		    			}
	        		    		}else if(fileType == 1){
	        		    			$("#qccgImg").html(createImg(result[i].filePath));
	        		    		}
	        		    	}
	        		    }
	        	 }else{
	        		 Layer.showFailMsg(data.msg);
	        	 }
	        }
		});
    }
});
function createImg(src) {
    var html = "";
    html += "<img onclick='photoPreview(this)' src='" + src + "'/>";
    return html;
}

// 图片点击预览
function photoPreview(obj) {
    var src = obj.getAttribute("src");
    layer.photos({
        photos: {
            title: "查看头像",
            data: [{
                src: src
            }]
        },
        shade: .01,
        closeBtn: 1,
        anim: 5
    })
}
